# words/models.py

from django.db import models

class Noun(models.Model):
    word = models.CharField(max_length=100, unique=True)
    sentence = models.TextField()
    chinese = models.CharField(max_length=255)
    chinese_sentence = models.TextField()
    level = models.IntegerField()
    m = models.BooleanField()
    gender = models.CharField(max_length=10)  # 允许多个性别，如 'f#m'
    plurals = models.CharField(max_length=100)


# words/models.py (示例)
class Verb(models.Model):
    word = models.CharField(max_length=100, unique=True)
    sentence = models.TextField()
    chinese = models.CharField(max_length=255)
    chinese_sentence = models.TextField()
    level = models.IntegerField()
    stark = models.BooleanField()
    divisible = models.BooleanField()
    reflexive = models.BooleanField()
    auxiliary = models.BooleanField()
    p1 = models.CharField(max_length=100)
    p2 = models.CharField(max_length=100)
    a1 = models.CharField(max_length=100)
    a2 = models.CharField(max_length=100)
    a3 = models.CharField(max_length=100)
    a4 = models.CharField(max_length=100)
    a5 = models.CharField(max_length=100)
    a6 = models.CharField(max_length=100)
    b1 = models.CharField(max_length=100)
    b2 = models.CharField(max_length=100)
    b3 = models.CharField(max_length=100)
    b4 = models.CharField(max_length=100)
    b5 = models.CharField(max_length=100)
    b6 = models.CharField(max_length=100)

    # 新增的字段 verb_class，用来表示动词的类别
    verb_class = models.IntegerField(default=0)

    def __str__(self):
        return self.word


class Adjective(models.Model):
    word = models.CharField(max_length=100, unique=True)
    sentence = models.TextField()
    chinese = models.CharField(max_length=255)
    chinese_sentence = models.TextField()
    level = models.IntegerField()

    def __str__(self):
        return self.word

class Other(models.Model):
    word = models.CharField(max_length=100, unique=True)
    sentence = models.TextField()
    chinese = models.CharField(max_length=255)
    chinese_sentence = models.TextField()
    level = models.IntegerField()

    def __str__(self):
        return self.word

class VerbConjugation(models.Model):
    VERB_TENSE_CHOICES = [
        ('present', '现在时'),
        ('past', '过去时'),
    ]

    PERSON_CHOICES = [
        ('a1', 'ich'),
        ('a2', 'du'),
        ('a3', 'er/es/sie'),
        ('a4', 'wir'),
        ('a5', 'ihr'),
        ('a6', 'sie/Sie'),
        ('b1', 'ich'),
        ('b2', 'du'),
        ('b3', 'er/es/sie'),
        ('b4', 'wir'),
        ('b5', 'ihr'),
        ('b6', 'sie/Sie'),
    ]

    verb = models.ForeignKey(Verb, on_delete=models.CASCADE, related_name='conjugations')
    form_type = models.CharField(max_length=10, choices=VERB_TENSE_CHOICES)
    person = models.CharField(max_length=2, choices=PERSON_CHOICES)
    conjugated_form = models.CharField(max_length=100)

    def __str__(self):
        return f"{self.verb.word} - {self.form_type} - {self.person}: {self.conjugated_form}"

# 新增的同义词相关模型

class Synset(models.Model):
    id = models.AutoField(primary_key=True)
    is_visible = models.BooleanField(default=True)

    class Meta:
        db_table = 'synset'
        managed = False

class Term(models.Model):
    id = models.AutoField(primary_key=True)
    synset = models.ForeignKey(Synset, on_delete=models.CASCADE)
    word = models.CharField(max_length=255)

    class Meta:
        db_table = 'term'
        managed = False

class SynsetLink(models.Model):
    id = models.AutoField(primary_key=True)
    synset = models.ForeignKey(Synset, related_name='links', on_delete=models.CASCADE)
    linked_synset = models.ForeignKey(Synset, related_name='linked_to', on_delete=models.CASCADE)
    link_type = models.IntegerField()

    class Meta:
        db_table = 'synset_link'
        managed = False

class TermLevel(models.Model):
    id = models.AutoField(primary_key=True)
    term = models.ForeignKey(Term, on_delete=models.CASCADE)
    level = models.CharField(max_length=50)

    class Meta:
        db_table = 'term_level'
        managed = False

class TermLink(models.Model):
    id = models.AutoField(primary_key=True)
    term = models.ForeignKey(Term, related_name='term_links', on_delete=models.CASCADE)
    linked_term = models.ForeignKey(Term, related_name='linked_terms', on_delete=models.CASCADE)
    link_type = models.IntegerField()

    class Meta:
        db_table = 'term_link'
        managed = False

class Category(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=255)

    class Meta:
        db_table = 'category'
        managed = False

class CategoryLink(models.Model):
    id = models.AutoField(primary_key=True)
    synset = models.ForeignKey(Synset, on_delete=models.CASCADE)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)

    class Meta:
        db_table = 'category_link'
        managed = False
